package com.m1905hd.user.entity;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author weiwei.huang
 * @email ihuangweiwei@163.com
 * @date 15/3/30
 */
public class User {

    private int id;
    private int organizationId;
    private String userName;
    private String password;
    private String realName;
    private String email;
    private String salt;
    private List<Integer> roleIds;
    private Date created = new Date();
    private Date lastLogin;
    private int available;


    public User() {
    }

    public User(String userName, String realName, String email) {
        this.userName = userName;
        this.realName = realName;
        this.email = email;
        this.lastLogin = new Date();
        this.available = 1;
        this.organizationId = 0;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getOrganizationId() {
        return organizationId;
    }

    public void setOrganizationId(int organizationId) {
        this.organizationId = organizationId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public List<Integer> getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(String roleIds) {
        if (StringUtils.isEmpty(roleIds)) {
            this.roleIds = Collections.emptyList();
        } else {
            String[] role_ids = roleIds.split(",");
            this.roleIds = new ArrayList<Integer>();
            for (String id : role_ids) {
                if (!StringUtils.isEmpty(id)) {
                    this.roleIds.add(Integer.valueOf(id));
                }
            }
        }
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    public int getAvailable() {
        return available;
    }

    public void setAvailable(int available) {
        this.available = available;
    }
}
